package view.frames;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

import model.Actions;
import utilities.EPatterns;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class MainAgentFrame extends javax.swing.JFrame {

	/**
	 * CONSTANTES
	 */
	private static final String PATTERN_ADVISOR_TITLE = "Welcome to the Pattern Advisor wizard";
	private static final String PATTERN_ADVISOR_SUB_TITLE = "Click Next to proceed.";
	private static final String PATTERN_ADVISOR_WIZARD_INTRO = "<html>This wizard will help you apply a Design Pattern in your solution...</html>";
		
	/**
	 * 
	 */
	private EPatterns pattern = EPatterns.AbstractFactory;
	private Actions actions;
	private String chain = new String();
	
	/**
	 * GUI
	 */
	private static final long serialVersionUID = 1L;
	private JLabel patternAdvisorTitle;
	private JLabel patternAdvisorSubTitle;
	private JLabel patternAdvisorWizardText;
	private JButton cancelButton;
	private JButton nextButton;
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				MainAgentFrame inst = new MainAgentFrame();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public MainAgentFrame() {
		super();
		chain = new String();
		initGUI();
	}
	
	public MainAgentFrame(EPatterns pattern, String chain, Actions actions) {
		super();
		this.pattern = pattern;
		this.chain = chain;
		this.actions = actions;
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			setPreferredSize(new Dimension(650, 420));
			this.setResizable(false);
			GridBagLayout thisLayout = new GridBagLayout();
			this.setTitle("Pattern Advisor - Welcome");
			thisLayout.rowWeights = new double[] {0.001, 0.01, 0.001};
			thisLayout.rowHeights = new int[] {1, 7, 1};
			thisLayout.columnWeights = new double[] {0.1};
			thisLayout.columnWidths = new int[] {7};
			this.setIconImage(new ImageIcon(getClass().getClassLoader().getResource("resources/icons/wizard.png")).getImage());
			getContentPane().setLayout(thisLayout);
			getContentPane().setBackground(new java.awt.Color(255,255,255));
			setLayout(new BorderLayout());
			JLabel background=new JLabel(new ImageIcon(getClass().getClassLoader().getResource("resources/images/background_Main_1.png")));
			add(background);
			background.setLayout(thisLayout);

			{
				
				patternAdvisorTitle = new JLabel();
				patternAdvisorTitle.setText(PATTERN_ADVISOR_TITLE);
				patternAdvisorTitle.setFont(new Font("Curier New", 1, 22));
				background.add(patternAdvisorTitle, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(15, 10, 0, 0), 0, 0));
			}
			{
				
				patternAdvisorWizardText = new JLabel();
				patternAdvisorWizardText.setText(PATTERN_ADVISOR_WIZARD_INTRO);
				patternAdvisorWizardText.setFont(new Font("Curier New", 0, 13));
				background.add(patternAdvisorWizardText, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(20, 20, 0, 0), 0, 0));
			}
			{
				
				patternAdvisorSubTitle = new JLabel();
				patternAdvisorSubTitle.setText(PATTERN_ADVISOR_SUB_TITLE);
				patternAdvisorSubTitle.setFont(new Font("Curier New", 0, 12));
				background.add(patternAdvisorSubTitle, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.SOUTHWEST, GridBagConstraints.NONE, new Insets(0, 20, 10, 0), 0, 0));
			}
			{
				nextButton = new JButton();
				nextButton.setIcon(new ImageIcon(getClass().getClassLoader().getResource("resources/icons/next.png")));
				nextButton.setText("Next");
				nextButton.setToolTipText("Press Yes to continue");
				nextButton.setFont(new Font("Curier New",0,12));
				nextButton.addMouseListener(new MouseAdapter() {
					public void mousePressed(MouseEvent evt) {
						nextButtonMousePressed(evt);
					}
				});
				background.add(nextButton, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, -5, 140), 15, 0));
			}
			{
				cancelButton = new JButton();
				cancelButton.setIcon(new ImageIcon(getClass().getClassLoader().getResource("resources/icons/cancel.png")));
				cancelButton.setText("Cancel");
				cancelButton.setToolTipText("Press Cancel to exit the wizard");
				cancelButton.setFont(new java.awt.Font("Curier New",0,12));
				cancelButton.addMouseListener(new MouseAdapter() {
					public void mousePressed(MouseEvent evt) {
						cancelButtonMousePressed(evt);
					}
				});
				background.add(cancelButton, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, -5, 20), 0, 0));
			}
					
			pack();
			setSize(650, 420);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}

	protected void cancelButtonMousePressed(MouseEvent evt) {
		this.dispose();
	}

	protected void nextButtonMousePressed(MouseEvent evt) {
		
		this.dispose();
		
		JFrame patternRecommendator;
		
		if (pattern.equals(EPatterns.StateAndStrategy)) {			
			patternRecommendator = new CustomPatternRecommendatorFrame(chain,actions);
		}
		else {
			patternRecommendator = new PatternRecommendatorFrame(pattern,chain,actions);
		}
		
		patternRecommendator.setLocationRelativeTo(null);
		patternRecommendator.setVisible(true);
		
	}

}
